<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BAWePoll
 *
 * @author Jianfeng
 */
class BAWePollCooker extends BATypedEventCooker {

    protected function getTypeOwnerName() {
        return 'wePoll';
    }

    protected function getOwnerTableName() {
        return 'wePoll';
    }

    protected function getPollTable($pollType = NULL) {

        $oPollType = NULL;
        $pollTable = NULL;
        if ($pollType != NULL) {
            $oPollType = $this->getType($pollType);
        }
        $tableName = $this->getOwnerTableName();
        if ($oPollType != NULL) {
            $pollTable = new BASheet($tableName, $oPollType);
        } else {
            $pollTable = new BASheet($tableName, BTreeTable::All_Owner);
        }

        return $pollTable;
    }

    public function getPollList($operationName = NULL) {

        if ($operationName == NULL) {
            $operationName = Blyn::app()->getActiveOperation()->getName();
        }

        $treeTable = $this->getPollTable($this->getCurrentType());

        $itemData = array();
        if ($operationName != 'admin') {
            $itemData['operation'] = $operationName;//can show different list for customer and member
        }

        $view = $treeTable->getView(array('itemData' => $itemData));

        return $view;
    }

    public function onShowPollList($operationName = NULL) {

        $viewName = 'poll_list';

        /*
        if ($operationName == 'admin') {
            $viewName = 'poll_list';
        }
         * 
         */

        $pollList = $this->getPollList();

        $this->updateControl->addRenderView('pollList', $viewName, array('pollList' => $pollList));
    }

    public function onShowAddPoll() {
        
    }

    public function onAddPoll() {
        
    }

    public function onShowUserPoll() {
        
    }

    public function onUserPoll() {
        
    }

    public function onShowAdminHome() {
        $this->onShowPollList('admin');
    }

    public function onShowCustomerHome() {
        $this->onShowPollList('customer');
    }

    public function onShowMemberHome() {
        $this->onShowPollList('member');
    }

}
